<div class="layui-fluid">
	<div class="layui-row">
		<div class="layui-col-xs12">
			<div class="layui-card layui-backbox">
				<div class="layui-card-header">新增名师交流</div>
				<div class="layui-card-body" style="display: flex;">
					<form class="layui-form" action="/" lay-filter="richfilter">
						<input type="hidden" name="tbId">
				

						<div class="layui-form-item">
							<label class="layui-form-label">问题详情</label>
							<div class="layui-input-inline">
								<textarea id="demo" name="content1" style="display: none;"></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">讲师回答</label>
							<div class="layui-input-inline">
								<textarea id="demo2" name="content2" style="display: none;"></textarea>
							</div>
						</div>

						<div class="layui-form-item">
							<div class="layui-input-block">

								<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
								<div class="layui-btn layui-btn-primary" id="returnqx">取消</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- 脚本 -->
<script>
	layui.use(['form', 'layedit'], function() {
		var form = layui.form,
			$ = layui.jquery,
			layedit = layui.layedit;
		form.render();
		var richdemo = layedit.build('demo');
			var richdemo2 = layedit.build('demo2');
		var router = layui.router();
		if(router.search.tbId){
			// 有id的传参的值  查询 id
			POSTAJAX(AgreementGetById, {
				tbId: router.search.tbId
			}, function(res) {
				form.val("richfilter", {
					"tbTitle": res.data.tbTitle // "name": "value"
						,"tbAgreementType": res.data.tbAgreementType
				})
				layedit.setContent(richdemo, '111');

			})
			
			//修改
			form.on('submit(formDemo)', function(data) {
				if (layedit.getContent(richdemo) == '') {
					layer.msg("请输入详情内容", {
						"icon": 7
					})
				} else {
					data.field.tbAgreementContent = layedit.getContent(richdemo)
					data.field.tbId = router.search.tbId;
					POSTAJAX(AgreementMod, data.field, function(res) {
						if (res.status == 200) {
							layer.msg("修改成功", {
								"icon": 1
							})
							richdemo = layedit.build('demo');
							form.render();
							location.href = '#/setup/list'
						} else {
							layer.msg("失败，请重试", {
								"icon": 2
							})
						}
					})
				}
				return false;
			});
			
		}else{
			// 新增
					//监听提交
			form.on('submit(formDemo)', function(data) {
				if (layedit.getContent(richdemo) == '' || layedit.getContent(richdemo2) == '') {
					layer.msg("请输入详情内容", {
						"icon": 7
					})
				} else {
					data.field.content1 = layedit.getContent(richdemo)
								data.field.content2 = layedit.getContent(richdemo2)
								data.field.tbId = router.search.videotbId;
								console.log(data.field)
					POSTAJAX(insertTbTeacherCommunication, data.field, function(res) {
						if (res.status == 200) {
							layer.msg("新增成功", {
								"icon": 1
							})
							richdemo = layedit.build('demo');
							form.render();
							// location.href = '#/setup/list'
						} else {
							layer.msg("失败，请重试", {
								"icon": 2
							})
						}
					})
				}
				return false;
			});
			
		}
		$("#returnqx").on("click", function() {
			location.href = '#/setup/list';
		
		})


	});
</script>
<!-- 样式 -->
<style scoped>
	.layui-form-item .layui-input-inline {
		float: left;
		width: 600px;
		margin-right: 10px;
	}
</style>
